package com.redrose.audioandvideo.ui.activitys;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.alibaba.android.arouter.launcher.ARouter;
import com.redrose.audioandvideo.R;
import com.redrose.audioandvideo.databinding.ActivityLoginBinding;
import com.redrose.audioandvideo.utils.LogUtils;


/**
 * Desc:
 * @author: RedRose
 * Date: 2019/5/19 0019
 * Email: yinsxi@163.com
 */
public class LoginActivity extends BaseActivity<ActivityLoginBinding> {
    String[] permissoons = new String[]{
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE
    };
    @Override
    public void initData() {
        setRightTitle(getString(R.string.register));
        setLeftTitle(getString(R.string.close));
        hideToolBar();
        mBinding.setLoginHandler(new LoginHandler());
        hideBack();
    }
    @Override
    public int setLayout() {
        initState();
        return R.layout.activity_login;
    }
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(!hasPermission(permissoons[0])){
            requestPeermission(permissoons,1000);
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        LogUtils.d(TAG,"  LoginActivity--- onDestroy");
    }


    public class LoginHandler{

        public void login(){
            ARouter.getInstance()
                    .build("/activity/main")
                    .withString("name","秋不白")
                    .withInt("age",26)
                    .navigation();

        }
        public void test(){
            if (!hasPermission(permissoons[0])) {
                requestPeermission(permissoons, 0);
            }else {
//                ARouter.getInstance()
//                        .build("/activity/test")
//                        .withString("name", "秋不白")
//                        .withInt("age", 26)
//                        .navigation();
            }
        }
        public void openCamera(){
//            ARouter.getInstance()
//                    .build("/activity/camera")
//                    .navigation();
        }
        public void openImages(){
//            ARouter.getInstance()
//                    .build("/activity/images")
//                    .navigation();
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if(requestCode == 1000){
            LogUtils.init();
        }
    }
}
